import React, { useEffect, useState } from 'react';
import { AxColumnEnum, AxTable } from '@/components/AxList';
import AxOperationButton from '@/components/AxList/AxOperationButton';
import { AxCard } from '@/components/AxBase';
import { axconst } from '@/shared/axconst';
import { axhttp } from '@/shared/axhttp';
import { axurl } from '@/shared/axurl';

const { getX } = axhttp;
const url = axurl.center.s.flow.need;
const Index: React.FC<any> = props => {
    const { handleSelectLeft } = props;
    const [data, setData] = useState<any>(axconst.initialList);
    const [loading, setLoading] = useState<any>(false);

    useEffect(() => {
        handleRead();
    }, []);

    const handleRead = () => {
        setLoading(true);
        /** state 1待办 2已办 3发起 */
        getX(url.readFlowTypeList, { state: 1 }).then((res: any) => {
            setData({
                list: res.data.map((m: any) => ({
                    ...m,
                    id: m.workFlowType,
                })),
                success: true,
            });
        }).finally(() => {
            setLoading(false);
        });
    }

    /** 配置列 */
    const columns = [
        {
            title: '类型',
            dataIndex: 'workFlowType',
            width: axconst.width.seven,
            // render: (val: any) => <AxColumnEnum enumName='workFlowType' value={val} />,
        },
        {
            title: '数量',
            dataIndex: 'count',
        },
    ];

    /** 配置操作按钮 */
    const buttons = [
        {
            text: '刷新',
            icon: 'redo',
            type: 'primary',
            onClick: () => handleRead(),
        },
    ];

    const operationProps = {
        buttons: buttons,
        advanceSearch: false,
    };

    return (
        <AxCard flex={24}>
            <AxOperationButton {...operationProps} />
            <AxTable
                checkboxFixed={false}
                checkboxType='radio'
                loading={loading}
                data={data}
                columns={columns}
                showPagination={false}
                onSelectRow={handleSelectLeft}
                selectFirstRecord={true}
            // onChange={handleTableChange}
            // onDoubleClick={onDoubleClick}
            // {...rest}
            />
        </AxCard>
    );
};

export default Index;
